﻿using AutomaticPush.Common;
using AutomaticPush.Models;
using AutomaticPush.Quartz;
using AutoPushExt.Common;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace AutomaticPush.Services
{
    public static class IServiceExtension
    {

        /// <summary>
        /// 推送服务注册
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddPushService(this IServiceCollection services)
        {

            IConfigurationRoot ConfigRoot = AppConfig.Configuration;
            services.Configure<Configs>(ConfigRoot);

            GlobalData gd = GetGlobalData();
            services.AddSingleton(gd);//写入全局信息
            services.AddHttpClient();

            services.AddSingleton<WebApiExt>();//注册web接口访问类
            services.TryAddSingleton<QuartzHostService>();//注册自动任务单列模式

            services.AddSingleton<PushFrom>();//将窗体改成单列模式，便于信息推送
            services.AddDistributedMemoryCache();

            return services;

        }

        private static GlobalData GetGlobalData()
        {
            GlobalData gd = new GlobalData();
            gd.AllAssembly = Utils.GetAllAssembly();
            return gd;
        }

    }
}
